package io.github.uicdb.et.block;

import io.github.uicdb.et.ModMenuAndScreens;
import lombok.Getter;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

@Getter
public class ElementMenu extends AbstractContainerMenu {
    private final Container container;
    private final ContainerData containerData;
    private final BlockPos pos;
    public ElementMenu(int containerId, Inventory playerInventory, Container container, ContainerData containerData, FriendlyByteBuf buf) {
        super(ModMenuAndScreens.ELEMENT.get(), containerId);
        this.container = container;
        this.containerData = containerData;
        this.addDataSlots(containerData);
        container.startOpen(playerInventory.player);
        for (int i = 0; i < 9; i++) {
            addSlot(new Slot(container, i, 8+i*18, 76));
        }
        addSlot(new ResultSlot(container, 9, 8+9*18, 76));
        addPlayerInventory(playerInventory, 8, 114);
        this.pos = buf.readBlockPos();
    }
    public ElementMenu(int containerId, Inventory playerInventory, FriendlyByteBuf buf) {
        this(containerId,playerInventory,new SimpleContainer(10),new SimpleContainerData(7),buf);
    }
    private void addPlayerInventory(Inventory playerInventory, int x, int y) {
        for (int yIndex = 0; yIndex < 3; yIndex++) {
            for (int xIndex = 0; xIndex < 9; xIndex++) {//9-35
                this.addSlot(new Slot(playerInventory, xIndex + yIndex * 9 + 9, x + xIndex * 18, y + yIndex * 18 ));
            }
        }

        for (int xIndex = 0; xIndex < 9; xIndex++) {//0-8
            this.addSlot(new Slot(playerInventory, xIndex, x + xIndex * 18, y + 58));
        }
    }
    @Override
    public ItemStack quickMoveStack(Player player, int i) {
        return ItemStack.EMPTY;
    }

    @Override
    public boolean stillValid(Player player) {
        return true;
    }
}
